﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using METU_CMT.Business;

namespace METU_CMT
{
    public partial class StudentProfileScreen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindStudentInfo();
                BindCourses();
            }
        }

        private void BindStudentInfo()
        {
            Student _student = (Student) EntityFactory.User;
            SetStudentInfo(_student);
        }

        private void SetStudentInfo(Student student)
        {
            imgStudent.ImageUrl = student.PhotoFile;

            lblUserName.Text = student.UserName;
            lblNameSurname.Text = student.Name + " " + student.Surname;
            lblEMail.Text = student.Email;
        }

        protected void OnLnkBtnEditProfileClicked(object sender, EventArgs e)
        {
            Response.Redirect("~/EditProfileScreen.aspx");
        }

        private void BindCourses()
        {
            Student _student = (Student)EntityFactory.User;
            dtgCourses.DataSource = EntityFactory.GetCourseOfStudent( _student.UserId );
            dtgCourses.DataBind();
        }

        protected void OnLnkBtnCourseNameClicked(object sender, EventArgs e)
        {
            int _courseId = CommonMethods.GetIdFromGridViewRow((GridViewRow)(((LinkButton)sender).NamingContainer));
            EntityFactory.CourseId = _courseId;
            Course _course = new Course(_courseId);
            _course.GoToCourseMainPage(Response);
        }

    }
}